package com.lgl.allpeoplevent.util;

import com.lgl.scsapi.system.model.PageData;
import com.lgl.scsapi.vent.model.VentUser;
import org.springframework.util.StringUtils;

import java.util.Calendar;
import java.util.List;

/**
 * controller类的工具类
 */
public class ControllerUtil {

    /**
     * 设置统计参数
     * @param user 登录用户
     * @param year 统计的年份
     */
    public static PageData getCountParam(VentUser user, Integer year){
        PageData countPd = new PageData(6);
        if (StringUtils.isEmpty(year) || year < 2000){
            Calendar calendar = Calendar.getInstance();
            year = calendar.get(Calendar.YEAR);
        }
        String monthDay = "-01-01";
        countPd.put("startDate",year + monthDay);
        countPd.put("endDate",(year + 1) + monthDay);
        countPd.put("userId",user.getUserId());
        return countPd;
    }

    /**
     * 返回统计参数结果
     * @param countPd 要返回的PageData对象
     * @param countDataList 要返回的数据集
     * @return PageData对象
     */
    public static PageData countResult(PageData countPd, List<PageData> countDataList){
        countPd.clear();
        countPd.put("status",0);
        countPd.put("data", countDataList);
        return countPd;
    }
}